#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2025/3/20
# @USER    : Shengji He
# @File    : StrictlyPalindromicNumber.py
# @Software: PyCharm
# @Version  : Python-
# @TASK:

"""
- Math
- Two Pointers
- Brainteaser
"""


class Solution:
    """
    [2396. Strictly Palindromic Number](https://leetcode.com/problems/strictly-palindromic-number/description/)

    An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is palindromic.

    Given an integer n, return true if n is strictly palindromic and false otherwise.

    A string is palindromic if it reads the same forward and backward.

    Example 1:
        Input: n = 9
        Output: false
        Explanation: In base 2: 9 = 1001 (base 2), which is palindromic.
        In base 3: 9 = 100 (base 3), which is not palindromic.
        Therefore, 9 is not strictly palindromic so we return false.
        Note that in bases 4, 5, 6, and 7, n = 9 is also not palindromic.
    Example 2:
        Input: n = 4
        Output: false
        Explanation: We only consider base 2: 4 = 100 (base 2), which is not palindromic.
        Therefore, we return false.

    Constraints:
        - 4 <= n <= 105
    """

    def isStrictlyPalindromic(self, n: int) -> bool:
        for cur_base in range(2, n - 1):
            cur_n = n
            out_base = []
            while cur_n >= cur_base:
                out_base.append(cur_n % cur_base)
                cur_n = cur_n // cur_base
            out_base.append(cur_n)
            if out_base != out_base[::-1]:
                return False
        return True

    def isStrictlyPalindromic_v2(self, n: int) -> bool:
        """base=n-2, out=12, not palindromic number!"""
        return False


if __name__ == '__main__':
    n = 9
    S = Solution()
    print(S.isStrictlyPalindromic(n))
    print('done')
